Introduction
In the last post, we learned about some of the core features of functional programming in F#. In this post we are going to concentrate on functions.
A function has the following rules:
Always returns the same output for the same input
Has no side effects
Has one input and one output
Has immutable input and output
Pure functions that satisfy these rules have many benefits; They are easy to test, are cacheable and parallelizable. However, you application cannot consist only of pure functions as you probably have side effects like user input or persisting to a database.
If you read the previous post, you will remember that we wrote a function that had two parameters. I will show you why that fact and the one input rule are not conflicting. I said in the last post that function signatures are very important; In this post you will see why.
You can do a lot in a single function but you can do more and have better modularity by combining a few smaller functions together. We call this Function Composition.
Function Composition - Theory
We have two functions (f1 and f2) that look like this pseudocode: